<script setup>
import {Link} from "@element-plus/icons";
import {ref} from "vue";
import axios from "axios"
import {ElIcon, ElNotification} from "element-plus";
import {useRouter} from "vue-router"

function handleLinkClick() {
  window.open("https://gitee.com/shangchengmeiying/database-study");
}

let form = {
  username: "",
  password: ""
}
const formRef = ref(form);
const divConsole = ref(null);
let router = useRouter()

function login() {
  let formDate = new FormData()
  formDate.append("username", form.username)
  formDate.append('password', form.password)
  axios.post(import.meta.env.VITE_APP_BASE_URL + "/api/login", formDate, {
    timeout: 1000,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  }).then(res => {
    if (res.data.status === 200) {
      router.push({
        path: "/homePage", query: {
          token: res.data.token
        }
      })
    } else {
      ElNotification({
        title: 'error',
        message: res.data.err,
      })
      formRef.value.password = ""
      formRef.value.username = ""
    }

  }).catch(err => {
    ElNotification({
      title: 'error',
      message: 'unknown error happen:'+err,
    })
  })

}

</script>
<template>
  <div class="wrapper">
    <div class="header">
      <el-icon
          :size="25"
          :style="{ float: 'right', marginRight: '30px' }"
          color="#66ccff"
          @click="handleLinkClick"
      >
        <Link/>
      </el-icon>
    </div>
    <div class="body">
      <div class="mainWrapper">
        <div>
          <div class="title">
            员工人事调动管理系统
          </div>
          <div class="underLine"/>
          <div class="minTitle">
            Staff personnel transfer management system
          </div>
        </div>
        <div class="form">
          <el-form
              ref="form1"
              :model="formRef"
              label-width="120px"
              label-position="top"
          >
            <el-form-item label="user name" size="medium">
              <el-input v-model="formRef.username"></el-input>
            </el-form-item>
            <el-form-item label="password" size="medium">
              <el-input v-model="formRef.password" show-password></el-input>
            </el-form-item>
            <el-form-item
                :style="{marginTop:'60px'}"
            >
              <el-button type="primary" @click="login">
                Login
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="console" ref="divConsole">

        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.wrapper {
  width: 100%;
  height: 100%;
  /*background-color: #42b983;*/
}

.header {
  height: 15px;
  margin-bottom: 30px;
  margin-top: 20px;
}

.form {
  width: 500px;
  align-items: center;
  justify-content: center;
  margin-top: 50px;
  margin-left: 15px;
}

.mainWrapper {
  height: 700px;
  background-color: white;
  margin: 10px;
  border-radius: 20px;
  align-items: center;
  display: flex;
  flex-direction: column;
  padding-top: 20px;
  border: 1px solid #b5e5fd;
}

.body {
  width: 900px;
  margin: auto;
}

.title {
  font-size: 25px;
  font-weight: 700;
  /* margin-top:20px; */
  /* text-decoration:underline */
}

.underLine {
  height: 2px;
  width: 150px;
  margin: auto;
  background-color: #51a3cc;
}

.minTitle {
  font-size: 11px;
  margin-top: 5px;
}

.console {
  height: 50px;
  width: 100%;
}
</style>
